function note_view(id) {
    this.id = id;
    this.div = '#'+id+'_note-view';
    this.content = this.div + ' .note-view-content'
    this.init = function () {
        //note_view.bind_add_block_btn_click();
    };
    this.bind_add_block_btn_click = function (){
        var _this = this;
        $('#block-new-btn').click(function () {
            _this.add_block('');
        });
    };
    
    this.add_block = function (str) {
        this.save_status();
        var _this = this;
        add_block_do (global.crr_note_id, str,
        function (state, data){
            var id = data['id'];

            $(_this.content).find('ul').prepend(
                form_block(id, str)
            );

            update_block_tag_list_do(id);

            //actions
            block_items_dragsort_bind();
            block_items_mousedown_bind();
            block_item_contents_click_bind();
            block_item_remove_btn_click_bind();
            block_items_hover_bind();
            block_tag_btns_click_bind();
            notify('Add block ...done');    
        },
        function (state, data){
            notify('Add block  failed!.')
        });
    };

    this.save_status = function () {
        if (global.note_status != 0) {
            this.save_block_pos();
            this.save_block_content();
            global.note_status = 0;
        }
    };

    this.save_block_content = function () {
        $(this.content).find('.block-item-content')
        .each(function (i, elem) {
            var id = $(this).attr('id').split('_')[0];
            var content = $(this).html();
            save_block_content_do(id, content,
                function (state, data) {
                    result = true;
                },
                function (state, data) {
                    result = false;
                });

        });
    };

    this.save_block_pos = function() {
        var ord_list = new Array();
        block_items = $('#note-view ul').find('.block-item');
        for (var i = 0; i < block_items.length; i += 1) {
            ord_list.push(parseInt($(block_items[i]).attr('id').toString().split('_')[0]));
        }
        save_block_pos_do('[' + ord_list.toString() + ']',
            function (state, data) {
                notify('Save block position...done');    
            },
            function (state, data) {
                notify('Save block position failed!.')
            });
    },

    this.update_block_list = function () {
        var _this = this;
        get_block_list_do (this.id, 
        function (state, data) {
            var blocks = eval(data);
            var blocks_array = new Array();
            blocks_array.push('<ul>');
            for (var i = 0; i < blocks.length; i += 1) {
                blocks_array.push(
                    form_block(blocks[i].id, blocks[i].content)
                );
            }
            blocks_array.push('</ul>');
            $(_this.content).html(blocks_array.join(''));

            for (var i = 0; i < blocks.length; i += 1) {
                update_block_tag_list_do(blocks[i].id);
            }
            //actions
            block_items_dragsort_bind();
            block_items_mousedown_bind();
            block_item_contents_click_bind();
            block_item_remove_btn_click_bind();
            block_items_hover_bind();
            block_tag_btns_click_bind();
        },
        function (state, raw) {
            notify('Load block list fail');  
        });
    };
    this.init();
};

